home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / lib2to3 / fixes / fix_reduce.py < prev    next >
Encoding:
Python Source  |  2009-04-18  |  816 b   |  34 lines

  1. # Copyright 2008 Armin Ronacher.
  2. # Licensed to PSF under a Contributor Agreement.
  3.  
  4. """Fixer for reduce().
  5.  
  6. Makes sure reduce() is imported from the functools module if reduce is
  7. used in that module.
  8. """
  9.  
  10. from .. import pytree
  11. from .. import fixer_base
  12. from ..fixer_util import Name, Attr, touch_import
  13.  
  14.  
  15.  
  16. class FixReduce(fixer_base.BaseFix):
  17.  
  18.     PATTERN = """
  19.     power< 'reduce'
  20.         trailer< '('
  21.             arglist< (
  22.                 (not(argument<any '=' any>) any ','
  23.                  not(argument<any '=' any>) any) |
  24.                 (not(argument<any '=' any>) any ','
  25.                  not(argument<any '=' any>) any ','
  26.                  not(argument<any '=' any>) any)
  27.             ) >
  28.         ')' >
  29.     >
  30.     """
  31.  
  32.     def transform(self, node, results):
  33.         touch_import('functools', 'reduce', node)
  34.